Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure PromiseRejectionEvent has reason before logging it #1150

Merged
merged 2 commits into from
Mar 29, 2024

Conversation

bgrgicak
Copy link
Collaborator

Fixes #1149

What is this PR doing?

Checks if event.reason or event.reason.stack exist in logUnhandledRejection.

What problem is it solving?

Fixes a JS error when a promise without a reason is thrown.

How is the problem addressed?

By checking if a reason is provided.

Testing Instructions

  • Checkout this branch
  • Start Playground npm run dev
  • Open Playground and execute this in the browser console
Promise.reject();
  • Confirm that logger doesn't throw an error

@bgrgicak bgrgicak self-assigned this Mar 28, 2024
@bgrgicak bgrgicak requested a review from a team March 28, 2024 08:23
@bgrgicak bgrgicak added [Type] Bug An existing feature does not function as intended [Aspect] Website labels Mar 28, 2024
@@ -76,7 +76,12 @@ export class Logger extends EventTarget {
* @param PromiseRejectionEvent event
*/
private logUnhandledRejection(event: PromiseRejectionEvent) {
this.log(`${event.reason.stack}`, 'Error');
// No reason was provided, so we can't log anything.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this confirm the reason is not PHP fatal error but WASM crash? Or no need?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a great point! I will take some extra time to test it with the memory leak example and see if we can get some insights from the error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get any extra info here, so I will merge this PR as is.

@bgrgicak bgrgicak merged commit 907aa25 into trunk Mar 29, 2024
5 checks passed
@bgrgicak bgrgicak deleted the fix/1149-promise-reject-without-reason branch March 29, 2024 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Aspect] Website [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@php-wasm/logger event.reason is sometimes undefied
2 participants